package comparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : Test
 * @Author : 54061
 * @Date: 2022/2/10 9:43
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<String> box = new ArrayList<>();
        //准备牌
        String[] flowers = {"♠","♥","♣","♦"};
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        for (String flower : flowers){
            for (String number : numbers){
                String poke = flower + number;
                box.add(poke);
            }
        }
        box.add("joker");
        box.add("JOKER");
        ArrayList<String> 周润发 = new ArrayList<>();
        ArrayList<String> 周星驰 = new ArrayList<>();
        ArrayList<String> 刘德华 = new ArrayList<>();
        ArrayList<String> 地主牌 = new ArrayList<>();


        地主牌.add(box.get(box.size()-1));
        地主牌.add(box.get(box.size()-2));
        地主牌.add(box.get(box.size()-3));

        for (int i =0 ; i < box.size() - 3;i++){
            if (i % 3 == 0){
                周润发.add(box.get(i));
            }else if (i % 3 == 1){
                周星驰.add(box.get(i));
            }else{
                刘德华.add(box.get(i));
            }
        }


        //准备集合
        //实时final特性 : 当局变量在匿名内部类中使用的时候,就会被自定加上final -> 实时final
        ArrayList<Character> order = new ArrayList<>();

        Collections.addAll(order,'3','4','5','6','7','8','9','1','J','Q','K','A','2','o','O');

        Comparator<String> rule = new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return order.indexOf(o1.charAt(1)) - order.indexOf(o2.charAt(1));
            }
        };

        //清牌?? 偷梁换柱
        Collections.sort(周润发,rule);
        Collections.sort(周星驰,rule);
        Collections.sort(刘德华,rule);
        Collections.sort(地主牌,rule);

        //看牌
        System.out.println("周润发 = " + 周润发);
        System.out.println("周星驰 = " + 周星驰);
        System.out.println("刘德华 = " + 刘德华);
        System.out.println("地主牌 = " + 地主牌);
    }
}
